package com.zengdada.authority.utils.excel.export.title;

import com.zengdada.authority.utils.excel.export.style.MyCellStyle;
import com.zengdada.authority.utils.excel.export.style.MyCellStyleSize;
import org.apache.poi.ss.util.CellRangeAddress;

import java.awt.*;

/**
 * @author 12614
 * @contact 1261438511@qq.com
 * @date 2020-05-25 23:32
 * @describe excel 表头单元格
 */
public class CellTableTitle {
    private String title;
    private String fieldName;
    private int width = 1;
    private int height = 1;
    private int x = 0;
    private int y = 0;
    private MyCellStyleSize cellSize;
    private MyCellStyle cellStyle;

    public MyCellStyleSize getCellSize() {
        return cellSize;
    }

    public CellTableTitle setCellSize(MyCellStyleSize cellSize) {
        this.cellSize = cellSize;
        return this;
    }

    public MyCellStyle getCellStyle() {
        return cellStyle;
    }

    public CellTableTitle setCellStyle(MyCellStyle cellStyle) {
        this.cellStyle = cellStyle;
        return this;
    }

    public CellTableTitle(String title, String fieldName, int x, int y, int width, int height) {
        this.title = title;
        this.fieldName = fieldName;
        setSize(width, height);
        setPosition(x, y);
    }


    public CellTableTitle(String title, String fieldName, Point point, int width, int height) {
        this(title, fieldName, point.x, point.y, width, height);
    }

    public CellTableTitle(String title, String fieldName, int width, int height) {
        this(title, fieldName, 0, 0, width, height);
    }

    public CellTableTitle(String title, String fieldName) {
        this(title, fieldName, 0, 0, 1, 1);
    }

    public CellTableTitle(String title) {
        this(title, title, 0, 0, 1, 1);
    }

    public CellTableTitle(String title, int x, int y, int width, int height) {
        this(title, title, x, y, 1, 1);
    }

    public CellTableTitle(String title, Point point, int width, int height) {
        this(title, title, point.x, point.y, width, height);
    }

    public CellTableTitle(String title, int width, int height) {
        this(title, title, 0, 0, width, height);
    }

    public void setSize(int width, int height) {
        if (width > 1) {
            this.width = width;
        }
        if (height > 1) {
            this.height = height;
        }
    }

    public Point getPosition() {
        return new Point(x, y);
    }

    public CellRangeAddress getCellRangeAddress() {
        return new CellRangeAddress(x, x + this.height - 1, y, y + this.width - 1);
    }

    public void setPosition(Point point) {
        this.x = point.x;
        this.y = point.y;
    }

    public void setPosition(int x, int y) {
        this.x = x;
        this.y = y;
    }

    public String getTitle() {
        return title;
    }

    public String getFieldName() {
        return fieldName;
    }

    public int getWidth() {
        return width;
    }

    public int getHeight() {
        return height;
    }

    public int getX() {
        return x;
    }

    public int getY() {
        return y;
    }
}
